package org.jeecg.modules.demo.xxljob;


import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

/**
 * 模板导出
 */
public class Mobandaochu {

    public static TemplateExportParams getTemplateParams(String name){
        return new TemplateExportParams("D:\\opt\\template\\"+name+".xlsx");
    }

    public static Workbook fuza() {
        TemplateExportParams params = getTemplateParams("公司模板列表");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "员工信息");
        List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < 6; i++) {
            Map<String, Object> lm = new HashMap<String, Object>();
            lm.put("name", "王"+i);
            lm.put("age", "2"+i);
            lm.put("sex", i%2==0?"1":"2");
            lm.put("date",new Date());
            lm.put("salary", 1000+i);
            listMap.add(lm);
        }
        map.put("maplist", listMap);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        return workbook;
    }

    public static void main(String[] args) throws IOException {
        Workbook workbook = fuza();
        File savefile = new File("D:\\opt\\poi");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("D:\\opt\\poi\\result3.xlsx");
        workbook.write(fos);
        fos.close();
    }

}
